


import requests
import xmltodict
from requests.models import  Response
def response_to_dict(response:Response):
    '''
    获取response对象，将多种响应格式转化为dict
    :param response:
    :return:
    '''
    res_test = response.text
    if res_test.startswith("<?xml>"):
        final_res=xmltodict.parse(res_test)
    else:
        final_res=response.json()
    return final_res
#测试响应是否可以转换为dict
def response_dict():
    '''
    xml转化为json
    :return:
    '''
    res=requests.get("https://httpbin.ceshiren.com/get")
    r=response_to_dict(res)
    print(r)
    assert isinstance(r.dict)

response_dict()